package com.hliushi.learn.controller;

import com.hliushi.learn.annotation.Log;
import com.hliushi.learn.bean.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName AopController
 * @Description TODO
 * @Author hliushi
 * @Date 2021/7/7 10:22
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/aop")
public class AopController {

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * @param
     * @return
     */
    @ApiOperation(value = "testAop")
    @Log(module = "AopController", businessType = BusinessType.OTHER)
    @GetMapping("/{name}")
    public String testAop(@PathVariable String name) {
        return "hello " + name;
    }

    @ApiOperation(value = "打印信息")
    @Log(module = "AopController", businessType = BusinessType.OTHER)
    @GetMapping("/print-info")
    public ResponseEntity<String> printInfo(String username, String password) {
        Date date = new Date();
        String formatDate = sdf.format(date);

        log.info("username = {}, password = {}", username, password);
        return ResponseEntity.ok(formatDate);

    }

    @ApiOperation("打印信息222")
    @Log(module = "AopController", businessType = BusinessType.OTHER)
    @GetMapping("/info")
    public ResponseEntity<String> printInfo2(String username, String password) {
        Date date = new Date();
        String formatDate = sdf.format(date);

        log.info("username = {}, password = {}", username, password);
        return ResponseEntity.ok(formatDate);
    }
}
